﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Assign_Permissions.aspx.cs" Inherits="System_Assign_Permissions" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script src="../js/cascadeCheck.js" type="text/javascript"></script>
    <script type="text/javascript">
        var p_data = eval('(' + '<%= DATA_PERMISSION %>' + ')');
        var f_data = eval('(' + '<%= FLAG %>' + ')');
        var columns = [[{ field: "c", title: "组名称", width: 100 },
        { field: "p", title: "数据权限", width: 100, formatter: function (value, rec) {
            for (var d in p_data.Table1) { if (p_data.Table1[d].ID == value) return p_data.Table1[d].NAME; }
        }
        },
        { field: "f", title: "用户类型", width: 100, formatter: function (value, rec) {
            for (var d in f_data.Table1) { if (f_data.Table1[d].ID == value) return f_data.Table1[d].NAME; }
        }
        },
        { field: "u", title: "组等级", width: 100 }
        ]];

        var columns_d = [[{ field: "name", title: "菜单名称", width: 200 },
        { field: "o", title: "操作权限", width: 200, editor: { type: 'checkbox', options: { on: '只查看', off: ''}} }
        ]];

        function AjaxPost(method, obj, arr) {
            var dataArr1 = "{'d': '<%= MyStateManager.DomainID %>'" + arr + "}";
            $.ajax({
                url: "Assign_Permissions.aspx/" + method,
                data: dataArr1,
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (getdata) {
                    switch (obj) {
                        case "SelectClick":
                            SelectClick(getdata);
                            break;
                        case "BindTreeGrid":
                            BindTreeGrid(getdata);
                            break;
                        case "SaveDetail":
                            if (getdata.d == "1")
                                $.messager.alert('提示消息', '提交数据成功!', 'info');
                            break;
                    }
                },
                error: function (xhr) {
                    $.messager.alert('警告消息', xhr.responseText, 'warning');
                }
            });
        }

        function SelectClick(getdata) {
            if (getdata.d != "") {
                var data = eval('(' + getdata.d + ')');
                $('#Table_Group').datagrid('loadData', data);
            }
        }

        function BindTreeGrid(getdata) {
            if (getdata.d != "") {
                var dd = getdata.d.split('|');
                var data = eval('(' + dd[0] + ')');
                var data1 = eval('(' + dd[1] + ')');
                $('#m').tree('loadData', data);
                $('#o').tree('loadData', data1);
            }
        }
        var dataArr = "";
        function SaveGroup() {
            $.ajax({
                url: "Assign_Permissions.aspx/SaveGroup",
                data: dataArr,
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (getdata) {
                    if (getdata.d == "1") {
                        $.messager.alert('提示消息', '提交数据成功!', 'info');
                        close1();
                        AjaxPost("SelectGroupDate", "SelectClick", "");
                    }
                },
                error: function (xhr) {
                    $.messager.alert('警告消息', xhr.responseText, 'warning');
                }
            });
        }

        function load() {
            $('#Table_Group').datagrid({
                height: 450,
                rownumbers: true,
                columns: columns,
                fitColumns: true,
                singleSelect: true,
                toolbar: [{
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () { reset(); open1(); }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        if ($('#Table_Group').datagrid('getSelected') != null) { editGroup($('#Table_Group').datagrid('getSelected')); open1(); }
                        else { $.messager.alert('警告消息', '请选择一行数据.', 'warning'); }
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        if ($('#Table_Group').datagrid('getSelected') != null) {
                            $.messager.defaults.ok = '确认';
                            $.messager.defaults.cancel = '取消';
                            $.messager.confirm('提示消息', '确认删除数据?', function (b) { if (b) { getDataString(2); SaveGroup(); } });
                        }
                        else { $.messager.alert('警告消息', '请选择一行数据.', 'warning'); }
                    }
                }, '-', {
                    text: '保存数据权限',
                    iconCls: 'icon-save',
                    handler: function () {
                        if ($('#Table_Group').datagrid('getSelected') != null) { getSaveTree($('#Table_Group').datagrid('getSelected').ID); }
                        else { $.messager.alert('警告消息', '请选择一行数据.', 'warning'); }
                    }
                }],
                onSelect: function (i, r) {
                    AjaxPost("SelectDetailDate", "BindTreeGrid", ",'g':'" + r.ID + "'");
                }
            });
            $('#m').tree({
                checkbox: true
            });
            $('#o').tree({
                checkbox: true
            });
            $('#SaveGroup').window({
                title: '维护用户组数据',
                width: 400,
                minimizable: false,
                maximizable: false,
                collapsible: false,
                resizable: false,
                modal: true,
                top: ($(window).height() - 280) / 2
            });

            resetCombo();
            close1();
        }
        function getSaveTree(g) {
            var m = $('#m').tree('getChecked');
            var o = $('#o').tree('getChecked');
            var ms = new Array();
            var os = new Array();
            $.each(m, function (i, n) {
                if (!n.state) {
                    ms.push(n.id);
                    $.each(o, function (j, nn) {
                        if (nn.id == n.id) {
                            os.push(n.id); return false;
                        }
                    });
                }
            });
            AjaxPost("SaveOptionData", "SaveDetail", ",'g':'" + g + "','l':'<%= MyStateManager.UserID %>','m':'" + ms.join(',') + "','o':'" + os.join(',') + "'");
        }
        function editGroup(data) {
            $('#text1').val(data.c);
            $('#select1').combobox('setValue', data.p);
            $('#select2').combobox('setValue', data.f);
            $('#select3').combobox('setValue', data.u);
            $('#hidden1').val(data.ID);
        }

        function getDataString(i) {
            switch (i) {
                case 0:
                    dataArr = "{'i':'-1','d': '<%= MyStateManager.DomainID %>', 'l':'<%= MyStateManager.UserID %>','c':'" + $('#text1').val() + "','p':'" + $('#select1').combobox('getValue') + "','f':'" + $('#select2').combobox('getValue') + "','u':'" + $('#select3').combobox('getValue') + "'}";
                    break;
                case 1:
                    dataArr = "{'i':'" + $('#hidden1').val() + "','d': '<%= MyStateManager.DomainID %>', 'l':'<%= MyStateManager.UserID %>','c':'" + $('#text1').val() + "','p':'" + $('#select1').combobox('getValue') + "','f':'" + $('#select2').combobox('getValue') + "','u':'" + $('#select3').combobox('getValue') + "'}";
                    break;
                case 2:
                    dataArr = "{'i':'" + $('#Table_Group').datagrid('getSelected').ID + "','d': '-1', 'l':'<%= MyStateManager.UserID %>','c':'0','p':'0','f':'0','u':'0'}";
                    break;
            }
        }
        function reset() {
            $('#text1').val("");
            $('#hidden1').val("");
            resetCombo();
        }
        function resetCombo() {
            $('#select1').combobox({
                width: 130, editable: false, valueField: 'ID', textField: 'NAME', value: '1'
            });
            $('#select1').combobox('loadData', p_data.Table1);
            $('#select2').combobox({
                width: 130, editable: false, valueField: 'ID', textField: 'NAME', value: 'SR'
            });
            $('#select2').combobox('loadData', f_data.Table1);
            $('#select3').combobox('setValue', '0');
        }
        function open1() {
            $('#SaveGroup').window('open');
            $('#SaveGroup').css({ display: 'block' });
        }
        function close1() {
            $('#SaveGroup').window('close');
        }

        $(function () {
            AjaxPost("SelectGroupDate", "SelectClick", "");
            AjaxPost("SelectDetailDate", "BindTreeGrid", ",'g':'0'");
            load();
            $('#btn_SaveGroup').click(function () {
                if ($('#hidden1').val() == "") getDataString(0); else getDataString(1);
                SaveGroup();
            });
        });
    </script>
    <table id="wsd_inputtable">
        <tr>
            <td class="tabletitle" style="height: 21px" width="100%">
                用户组列表
            </td>
        </tr>
    </table>
    <table id="wsd_listtable">
        <tr>
            <td style="width: 40%">
                <table id="Table_Group">
                </table>
            </td>
            <td style="width: 200px;">
                <div id="p" class="easyui-panel" style="width: 250px; height: 450px;" title="模块权限"
                    iconcls="icon-save">
                    <ul id="m">
                    </ul>
                </div>
            </td>
            <td style="width: 200px;">
                <div id="Div1" class="easyui-panel" style="width: 250px; height: 450px;" title="操作权限"
                    iconcls="icon-save">
                    <ul id="o">
                    </ul>
                </div>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="font-weight: bolder;">
                <span style="color: Red; padding: 10px 0 0 10px;">特别说明:</span>1.进行修改,删除,保存数据权限操作时请先选择用户组列表中的一行数据.
                <p style="padding: 0 0 0 65px;">
                    2.模块权限是指用户组所拥有的对应模块是否可管理权限,勾选则表示可进行管理.</p>
                <p style="padding: 0 0 0 65px;">
                    3.操作权限是指用户组所拥有的对应模块<span style="color: Red;">是否只读权限</span>,勾选则表示为只读.</p>
                <p style="padding: 0 0 10px 65px;">
                    4.如果未指定模块权限的情况下,操作权限的分配则无效.</p>
            </td>
        </tr>
    </table>
    <div id="SaveGroup" class="easyui-window" icon="icon-save" style="width: 500px; height: 260px;
        padding: 5px; background: #fafafa; display: none;">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <div style="height: 40px;">
                    <label for="name" style="width: 90px; padding-left: 10px;">
                        用户组名称:</label>
                    <input class="easyui-validatebox" type="text" id="text1" required="true" missingmessage="此项为必填项!" /><span
                        style="color: Red; padding-left: 5px;">*</span>
                </div>
                <div style="height: 40px;">
                    <label for="email" style="width: 90px; padding-left: 10px;">
                        数据权限:</label>
                    <select class="easyui-combobox" id="select1">
                    </select>
                </div>
                <div style="height: 40px;">
                    <label for="name" style="width: 90px; padding-left: 10px;">
                        用户类型:</label>
                    <select class="easyui-combobox" id="select2">
                    </select>
                </div>
                <div style="height: 40px;">
                    <label for="name" style="width: 90px; padding-left: 10px;">
                        用户组等级:</label>
                    <select class="easyui-combobox" id="select3">
                        <option value="0">0</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                    </select>
                </div>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 30px;
                padding-top: 5px;">
                <input type="hidden" id="hidden1" />
                <a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="btn_SaveGroup">
                    提交</a> <a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)"
                        onclick="close1()">取消</a>
            </div>
        </div>
    </div>
</asp:Content>
